package com.open.dispatch;

import com.open.model.CodeGenerate;
import lombok.extern.slf4j.Slf4j;
import org.apache.velocity.VelocityContext;

/**
 * @author dashu
 * @date 2025/1/19 21:24
 * @description 代码生成器构造器
 */

@Slf4j
public class BuildDispatch {

    private static final CodeGenerateDispatch codeGenerateDispatch = new CodeGenerateDispatch();

    /**
     * 生成代码
     *
     * @param codeGenerate
     */
    public static void CreateModel(CodeGenerate codeGenerate) {
        try {
            //表名转类名
            codeGenerateDispatch.tablesNameToClassName(codeGenerate);
            VelocityContext context = new VelocityContext();
            //构建文件路径
            codeGenerateDispatch.buildPath(context, codeGenerate);
            //构建数据库相关
            codeGenerateDispatch.buildDataBase(context, codeGenerate);
            //生成文件
            codeGenerateDispatch.buildFile(context, codeGenerate);
        } catch (Exception e) {
            System.out.println("生成代码失败" + e);
        }
    }
}
